package com.hduong.springcloud.service.impl;

import com.hduong.springcloud.dao.AccountDao;
import com.hduong.springcloud.service.AccountService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;

/**
 * <h3>spring-cloud-demo-parent</h3>
 * <p>AccountService</p>
 *
 * @author : hduong
 * @version : 1.0
 * @date : 2020-03-23 09:59
 **/
@Service
@Slf4j
public class AccountServiceImpl implements AccountService {

    @Autowired
    private AccountDao accountDao;


    @Override
    public void decrease(Long userId, BigDecimal money) {

        log.info("------->account-service中扣减账户余额开始");
        //模拟超时异常，全局事务回滚
//        try {
//            Thread.sleep(30*1000);
//        } catch (InterruptedException e) {
//            e.printStackTrace();
//        }
        accountDao.decrease(userId, money);
        log.info("------->account-service中扣减账户余额结束");

    }
}
